$(document).ready(function(){
	
	$.ajax({
  		type: "post",
 		url: "wsq/SchedBase_getAllWDay.action",
  		success:function(data){
  			$.each(data.tbWorkDays,function(i,n){
  				$("<option value="+n.wdId+">"+n.wdType+"</option>").appendTo('#wdId');
			});
  		}
	});
	
	$.ajax({
  		type: "post",
 		url: "wsq/SchedBase_getAllSType.action",
  		success:function(data){
  			$.each(data.tbShiftTypes,function(i,n){
  				$("<option value="+n.psId+">"+n.psShift+"</option>").appendTo('#psId');
			});
  		}
	});
	
	$('#ADD_DUTY').click(function(){
		var wdId=$('#wdId option:selected').val();
		var psId=$('#psId option:selected').val();
		var duId=$('#duId').val();
		var duPhone=$('#duPhone').val();		
		
		if(wdId!==null && wdId.length!==0 && psId!==null &&  psId.length!==0 &&
				duId!==null && duId.length!==0){
		
		 $.ajax({
		 
  			type: "post",
  			url: "wsq/AddDuty_saveDuty.action",
 			data:{
 				  "wdId1":wdId,"psId1":psId,"duId1":duId
 				 },
 				 
  			success:showData
		 });
		}else{
			alert("带*号的必填！");
		}
	});
	
	function showData(data){
		if(data.ajaxRST=='1'){
			alert("保存成功");
		}else{
			alert("save duty failed!");
		}
	}
	
	$('#RESET_DUTY').click(function(){
		$('#mainFrame',window.parent.document).attr('src','wsq/AddDuty.jsp');
	});
	
	
	/*$("#addDutyForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
           form.submit();   //提交表单  
      // alert(88);
	},
		rules: {
        	'duty.tbWorkDay.wdId':'required',
        	'duty.tbShiftType.psId':'required',
        	'duty.duName':'required',
        	'duty.duPhone':{
        		reuqierd:false,
        		number: true 
            }			
		},
		messages: {
			'duty.tbWorkDay.wdId':"*必须选",
			'duty.tbShiftType.psId':"*必须选",
			'duty.duName':"*",
			'duty.duPhone':"数字"
		}
	});*/
	
});